#include <stack>
#include <iostream>
using namespace std;

template <typename T>
class MinStack {
  public:
    void push(const T &num) {
      stack.push(num);
      if (stack_min.empty() || num < stack_min.top()) {
        stack_min.push(num);
      } else {
        stack_min.push(stack_min.top());
      }
    }

    void pop() {
      stack.pop();
      stack_min.pop();
    }

    T& top() {
      return stack.top();
    }

    const T& top() const {
      return stack.top();
    }

    const T& min() const {
      return stack_min.top();
    }

    bool empty() const {
      return stack.empty();
    }

    size_t size() const {
      return stack.size();
    }

  private:
    std::stack<T> stack;
    std::stack<T> stack_min;
};

int main() {
  MinStack<int> min_stack;
  cout << "min " << "expect" << endl;
  min_stack.push(3);
  cout << min_stack.min() << " 3" << endl;
  min_stack.push(4);
  cout << min_stack.min() << " 3" << endl;
  min_stack.push(2);
  cout << min_stack.min() << " 2" << endl;
  min_stack.push(3);
  cout << min_stack.min() << " 2" << endl;
  min_stack.pop();
  cout << min_stack.min() << " 2" << endl;
  min_stack.pop();
  cout << min_stack.min() << " 3" << endl;
  min_stack.pop();
  cout << min_stack.min() << " 3" << endl;
  min_stack.push(0);
  cout << min_stack.min() << " 0" << endl;

  return 0;
}
